

package com.hazelcast.client.impl.protocol.codec.custom;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.Generated;
import com.hazelcast.client.impl.protocol.codec.builtin.CustomTypeFactory;
import com.hazelcast.client.impl.protocol.codec.builtin.ListMultiFrameCodec;
import com.hazelcast.client.impl.protocol.codec.builtin.StringCodec;

import static com.hazelcast.client.impl.protocol.ClientMessage.BEGIN_FRAME;
import static com.hazelcast.client.impl.protocol.ClientMessage.END_FRAME;
import static com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil.fastForwardToEndFrame;

@SuppressWarnings("unused")
@Generated("f3a837fa744d9ae7f8bf2a87f2a512ac")
public final class SchemaCodec {

    private SchemaCodec() {
    }

    public static void encode(ClientMessage clientMessage, com.hazelcast.internal.serialization.impl.compact.Schema schema) {
        clientMessage.add(BEGIN_FRAME.copy());

        StringCodec.encode(clientMessage, schema.getTypeName());
        ListMultiFrameCodec.encode(clientMessage, schema.getFields(), FieldDescriptorCodec::encode);

        clientMessage.add(END_FRAME.copy());
    }

    public static com.hazelcast.internal.serialization.impl.compact.Schema decode(ClientMessage.ForwardFrameIterator iterator) {
        // begin frame
        iterator.next();

        java.lang.String typeName = StringCodec.decode(iterator);
        java.util.List<com.hazelcast.internal.serialization.impl.compact.FieldDescriptor> fields = ListMultiFrameCodec.decode(iterator, FieldDescriptorCodec::decode);

        fastForwardToEndFrame(iterator);

        return CustomTypeFactory.createSchema(typeName, fields);
    }
}
